package com.uniandes.edu.co.interfaz.persona;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.event.TableModelEvent;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import com.uniandes.edu.co.dto.Persona;
import com.uniandes.edu.co.dto.Tsp;
import com.uniandes.edu.co.interfaz.mundo.Principal;




/**
 * This code was edited or generated using CloudGarden's Jigloo
 * SWT/Swing GUI Builder, which is free for non-commercial
 * use. If Jigloo is being used commercially (ie, by a corporation,
 * company or business for any purpose whatever) then you
 * should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details.
 * Use of Jigloo implies acceptance of these licensing terms.
 * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
 * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
 * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
@SuppressWarnings("serial")
//public class InterfazPersona extends javax.swing.JFrame {
public class InterfazPersona extends JDialog {
	private Principal principal;
	
    private JScrollPane jScrollPane1;
    private JLabel jLabel2;
    private JComboBox jComboBox1;
    private JButton jButton5;
    private JButton jButton2;
    private JLabel jLabel1;

    /**
     * Auto-generated main method to display this JFrame
     */
    /*public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                InterfazPersona inst = new InterfazPersona();
                inst.setLocationRelativeTo(null);
                inst.setVisible(true);
            }
        });
    }*/
    /*public InterfazPersona() {
        super();
        initGUI();
    }*/
    public InterfazPersona(Principal id) {
        super(id, true);
        principal = id;
        setTitle( "Consultar Persona" );
        initGUI();
    }


    private void initGUI() {
        try {
            setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            getContentPane().setLayout(null);
            {
                jScrollPane1 = new JScrollPane();
                getContentPane().add(jScrollPane1);
                final DefaultTableModel dm = new DefaultTableModel();
                List <Persona> lPersonas=Tsp.getSingleton().getPersonas();
                int filaTabla=0;
                if(lPersonas!=null){
                	filaTabla=lPersonas.size();
                }
                Object[][] tabla=new Object[filaTabla][3];
                Object[] encabezado=new Object[3];
                //encabezado[0]="Seleccionar";
                //encabezado[1]="Id Persona";
                //encabezado[2]="Nombre";
                //encabezado[3]="Rol";
                encabezado[0]="Id Persona";
                encabezado[1]="Nombre";
                encabezado[2]="Rol";
                
                for (int i=0;i<lPersonas.size();i++){
                	Persona persona=lPersonas.get(i);
                    /*tabla[i][0]=new JRadioButton("");
                    tabla[i][1]=("JD");
                    tabla[i][2]=("Juan David");
                    tabla[i][2]=("L. Planeacion");*/
                    tabla[i][0]=(persona.getIdPersona());
                    tabla[i][1]=(persona.getNombre());
                    tabla[i][2]=(persona.getRol());
                }
                dm.setDataVector(tabla, encabezado);

                TableModel jTable1Model =dm;
                JTable jTable1 = new JTable(dm) {
                    public void tableChanged(TableModelEvent e) {
                        super.tableChanged(e);
                        repaint();
                    }
                };

                /*ButtonGroup group1 = new ButtonGroup();
                for (int i = 0; i < dm.getRowCount(); i++)
                {
                    group1.add( (AbstractButton) dm.getValueAt(i, 0));
                }*/
               
                jTable1.setModel(jTable1Model);
                /*jTable1.getColumn("Seleccionar").setCellRenderer(
                        new RadioButtonRenderer());
                jTable1.getColumn("Seleccionar").setCellEditor(
                        new RadioButtonEditor(new JCheckBox()));*/
                jScrollPane1.setBounds(46, 216, 386, 228);
                jScrollPane1.setViewportView(jTable1);
                jTable1.setBounds(75, 153, 335, 196);
                jTable1.setPreferredSize(new java.awt.Dimension(383, 225));


            }
            {
                jLabel1 = new JLabel();
                getContentPane().add(jLabel1);
                jLabel1.setText("PERSONA");
                jLabel1.setBounds(46, 20, 386, 26);
                jLabel1.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
                jLabel1.setFont(new java.awt.Font("Tahoma",1,14));
                jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
                jLabel1.setHorizontalTextPosition(SwingConstants.CENTER);
            }
           
            
            {
                jButton2 = new JButton();
                getContentPane().add(jButton2);
                jButton2.setText("Consultar");
                jButton2.setBounds(341, 90, 91, 21);
                jButton2.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        
                    }
                });
            }
            {
                jButton5 = new JButton();
                getContentPane().add(jButton5);
                jButton5.setText("Regresar");
                jButton5.setBounds(341, 458, 91, 21);
                jButton5.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                       dispose();
                       //Principal.main(null);
                    }
                });
            }
            {
            	List <Persona> personas=Tsp.getSingleton().getPersonas();
				List <String> idPersonas=new ArrayList<String>();
				idPersonas.add("Todos");
				for (Persona per : personas) {
					idPersonas.add(per.getIdPersona());
				}
				ComboBoxModel jComboBox1Model = 
					new DefaultComboBoxModel(
							idPersonas.toArray());
            	jComboBox1 = new JComboBox();
            	getContentPane().add(jComboBox1);
            	jComboBox1.setModel(jComboBox1Model);
            	jComboBox1.setBounds(190, 90, 130, 23);
            	jComboBox1.addActionListener(new ActionListener() {
            		public void actionPerformed(ActionEvent evt) {
            			System.out.println("jComboBox1.actionPerformed, event="+evt);
            			//TODO add your code for jComboBox1.actionPerformed
            		}
            	});
            }
            {
            	jLabel2 = new JLabel();
            	getContentPane().add(jLabel2);
            	jLabel2.setText("Id de la Persona");
            	jLabel2.setBounds(46, 90, 119, 16);
            }

            pack();
            this.setSize(477, 524);
            centrarVentana();
        } catch (Exception e) {
            //add your error handling code here
            e.printStackTrace();
        }
    }
    
    private void centrarVentana(){
        Dimension dPantalla = Toolkit.getDefaultToolkit( ).getScreenSize( );
        Dimension dVentana = getSize( );

        int xEsquina = ( dPantalla.width / 2 ) - ( dVentana.width / 2 );
        int yEsquina = ( dPantalla.height / 2 ) - ( dVentana.height / 2 );

        setLocation( xEsquina, yEsquina );
    }

}
